package com.autumn.zero.authorization.application.services.impl;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import com.autumn.zero.application.services.AbstractZeroQueryAppService;
import com.autumn.zero.authorization.application.dto.users.UserLoginAttemptOutput;
import com.autumn.zero.authorization.application.services.IUserLoginAttemptAppService;
import com.autumn.zero.authorization.entitys.users.UserLoginAttempt;
import com.autumn.zero.authorization.repositorys.users.IUserLoginAttemptRepository;

/**
 * 
 * 用户登录尝试
 * 
 * @author 杨昌国 2018-12-11 16:28:20
 */
public class UserLoginAttemptAppServiceImpl
		extends AbstractZeroQueryAppService<Long, UserLoginAttempt, IUserLoginAttemptRepository, UserLoginAttemptOutput>
		implements IUserLoginAttemptAppService {

	@Autowired
	private IUserLoginAttemptRepository repository;

	@Override
	public String getModuleName() {
		return "用户登录尝试";
	}

	@Override
	protected IUserLoginAttemptRepository getQueryRepository() {
		return this.repository;
	}

	private Set<String> searchMembers = new HashSet<>();

	@Override
	protected Set<String> getSearchMembers() {
		if (searchMembers.size() == 0) {
			searchMembers.add(UserLoginAttempt.FILED_USER_ACCOUNT);
			searchMembers.add(UserLoginAttempt.FILED_CLIENT_IP_ADDRESS);
		}
		return searchMembers;
	}

	@Override
	public void deleteAll() {
		this.repository.truncateTable();
	}

}
